﻿using System.Collections.Generic;
using System.Linq;
using Contracts.Entities;

namespace Definition.WebImport
{
    internal class TmdbGetBackdrops
    {
        internal IEnumerable<byte[]> Find(IEnumerable<TmdbMovieImage> images)
        {
            var results = new List<byte[]>();
            var tmdbImages = images.Where((image) =>
                image.Type == "backdrop" 
                && image.Width == 780
                && image.Height == 439
                && image.Url.Contains("jpg"));

            for (int i = 0; i < tmdbImages.Count(); i++)
            {
                //Nicht mehr als 5 Backdrops downloaden
                if (i > 4)
                    break;

                var result = WebClientRequest.GetBytes(tmdbImages.ElementAt(i).Url);

                if (result != null)
                    results.Add(result);
            }

            return results;
        }
    }
}
